#{extends '/include/main.html' /}
<div class="form-page">
	<a href="@@{AdminController.listUsers()}" class="form-backto-result-button">返回</a>
	#{if user}
		<a class="form-reset-button hand" id="form-reset-button">重置密码</a>
	#{/if}
	<h2 class="form-title">用户管理</h2>
	#{if user}
		<form action="@@{AdminController.updateUser}?x-http-method-override=PUT" method="POST">
		<input type="hidden" name="userId" value="${user.id}" />
	#{/if} 
	#{else}
		<form action="@@{AdminController.saveUser}" method="POST">
	#{/else}
		<table class="form-submit-zone">
			<tbody>
				<tr>
					<th>用户名</th>
					<td>
						<input type="text" name="name" value="${(flash.name || flash.name == '') ? flash.name : (user ?.name)}" />
						<div class="error"><span>#{error 'name' /}</span></div>
					</td>
				</tr>
				<tr>
					<th>是否激活</th>
					<td>
						是:<input type="radio" name="isActive" value="true" #{if !user || user.isActive == true}checked#{/if}/>
						否:<input type="radio" name="isActive" value="false" #{if user && user.isActive == false}checked#{/if}/>
					</td>
				</tr>
				<tr>
					<th>提交</th>
					<td>
						<input type="submit" class="form-submit-zone-submit-button"/>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
#{if user}
	<script>
		$(function() {
			$("#form-reset-button").click(function() {
				$.ajax({
					url : "@@{AdminController.resetUser(user.id)}",
					type : "put",
					success : function() {
						alert("重置成功");
					}
				});
			});
		});
	</script>
#{/if}